"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const redux_1 = require("@tarojs/redux");
const taro_1 = require("@tarojs/taro");
const components_1 = require("@tarojs/components");
const taro_ui_1 = require("taro-ui");
const XGood_1 = require("../../components/XGood");
const YTableDivider_1 = require("../../components/YTableDivider");
const ProfileAvatar_1 = require("../../containers/ProfileAvatar");
const join1_2x_png_1 = require("../../assets/join1@2x.png");
const join2_2x_png_1 = require("../../assets/join2@2x.png");
const cloverActive_2x_png_1 = require("../../assets/cloverActive@2x.png");
const goods_1 = require("../../actions/goods");
require("./index.scss");
let Profile = class Profile extends taro_1.Component {
    constructor() {
        super(...arguments);
        this.config = {
            navigationBarTitleText: '详情'
        };
        this.state = {
            visible: false,
            isGrowCloverOpened: false,
            isLanchGoodsOpened: false,
        };
        this.onGetPhoneNumber = msg => {
            console.log(msg);
        };
        this.handleLaunchGoods = msg => {
            // 阻止事件冒泡
            msg.stopPropagation();
            this.setState(state => (Object.assign({}, state, { visible: !state.visible })));
        };
        this.onToShare = msg => {
            // 阻止事件冒泡
            msg.stopPropagation();
            console.log(msg, 'onToShare');
        };
        this.handleToPage = (pathName, e) => {
            e.stopPropagation();
            taro_1.default.navigateTo({
                url: pathName
            });
        };
        this.handleGrowClover = () => {
            this.setState(state => (Object.assign({}, state, { isGrowCloverOpened: true })));
        };
        this.handleLaunchGoods = () => {
            this.setState(state => (Object.assign({}, state, { isLanchGoodsOpened: true })));
        };
        this.onCurtainClose = () => {
            this.setState(state => (Object.assign({}, state, { isGrowCloverOpened: false, isLanchGoodsOpened: false })));
        };
        this.handleSubmits = () => {
            taro_1.default.showToast({ title: `开发ing...`, icon: 'loading' });
        };
    }
    componentWillReceiveProps(nextProps) {
        console.log(this.props, nextProps);
    }
    componentWillUnmount() { }
    componentWillMount() {
        this.props.fetchProfile(this.$router.params, (data) => {
            if (data.errno || typeof data === 'string') {
                taro_1.default.showToast({ title: `获取抽奖详情失败`, icon: 'none' });
            }
        });
        this.props.fetchUsers(this.$router.params);
    }
    componentDidMount() { }
    componentDidShow() { }
    componentDidHide() { }
    //分享按钮函数
    onShareAppMessage() {
        return {
            title: '幸运草小程序',
            path: 'pages/home/index',
            success(res) {
                console.log("转发成功:" + JSON.stringify(res));
            },
            fail(res) {
                console.log("转发失败:" + JSON.stringify(res));
            }
        };
    }
    render() {
        const goodsId = this.$router.params.id;
        const { visible } = this.state;
        const flag = this.props.goods.profile.data && new Date(this.props.goods.profile.data.endAt) < new Date(this.props.goods.profile.updateAt);
        return (<components_1.View className='profile'>
        <XGood_1.default data={this.props.goods.profile.data}/>
        <components_1.View className='article' style={{ backgroundColor: '#fff' }}>
          <YTableDivider_1.default title='抽奖说明'/>
          <components_1.View className='content' style={{ textAlign: 'justify' }}>
            <components_1.Text className='text'>{this.props.goods.profile.data.remark}</components_1.Text>
          </components_1.View>
          <YTableDivider_1.default title='奖品介绍'/>
          {this.props.goods.profile.data.GoodsFigures.map(item => {
            return <components_1.View className='content' key={item.id}>
                <components_1.Text className='text'>{item.figcaption}</components_1.Text>
                <components_1.Image src={item.image} mode='widthFix' className='image'/>
              </components_1.View>;
        })}
        </components_1.View>

        <components_1.View className='paihang'>
          <taro_ui_1.AtButton size='small' onClick={this.handleToPage.bind(this, `/pages/profile/Integrals`)}>种草排行</taro_ui_1.AtButton>
          {flag && <taro_ui_1.AtButton size='small' onClick={this.handleToPage.bind(this, '/pages/profile/Winnings')}>中奖名单 暂时展位</taro_ui_1.AtButton>}
        </components_1.View>

        <components_1.View className='profile-menu' onClick={this.handleSubmits}>
          <components_1.Text className='text'>参与抽奖</components_1.Text>
        </components_1.View>

        <components_1.View className='profile-avatar-title'>
          <components_1.Text className='text'>参与抽奖，种下幸运草</components_1.Text>
        </components_1.View>
        <ProfileAvatar_1.default data={this.props.goods.users}/>
        <components_1.View className='profile-avatar-brief' onClick={this.handleToPage.bind(this, '/pages/profile/Users')}>
          <components_1.Text className='text'>已有{this.props.goods.users.pagination.count}人参与</components_1.Text>
          <components_1.Text className='link'>&nbsp;&nbsp;查看全部 ></components_1.Text>
        </components_1.View>

        <taro_ui_1.AtList>
          <taro_ui_1.AtListItem title='我的幸运草 x6' arrow='right' extraText='继续种草' onClick={this.handleGrowClover}/>
        </taro_ui_1.AtList>

        <components_1.View className='profileBtnGroup'>
          <taro_ui_1.AtButton className='btn btn-first' type='secondary' size='small' onClick={this.handleLaunchGoods}>我也要发起</taro_ui_1.AtButton>
          <taro_ui_1.AtButton className='btn btn-last' type='primary' openType='share' size='small' onClick={this.onToShare}>分享给朋友</taro_ui_1.AtButton>
        </components_1.View>
        <taro_ui_1.AtCurtain isOpened={this.state.isGrowCloverOpened} onClose={this.onCurtainClose}>
          <components_1.Image src={join1_2x_png_1.default} mode='widthFix' className='image' style={{ width: '80%', marginLeft: '10%', marginTop: '20%' }}/>
          <components_1.View className='curtain-abs-grow'>
            <components_1.View className='inner'>
              <components_1.Text className='text'>我还有幸运草 x6</components_1.Text>
              <components_1.Image src={cloverActive_2x_png_1.default} mode='widthFix' className='icon'/>
            </components_1.View>
            <components_1.View className='footer'>
              <components_1.Text className='text'>我要再种</components_1.Text>
              <components_1.Input className='input'/>
              <taro_ui_1.AtButton size='small'>确认种草</taro_ui_1.AtButton>
              <components_1.Text className='more'>获得更多幸运草</components_1.Text>
            </components_1.View>
          </components_1.View>
        </taro_ui_1.AtCurtain>
        <taro_ui_1.AtCurtain isOpened={this.state.isLanchGoodsOpened} onClose={this.onCurtainClose}>
          <components_1.Image src={join2_2x_png_1.default} mode='widthFix'/>
          <components_1.View className='curtain-abs-success'>
            <components_1.View className='inner'>
              <components_1.Text className='text'>您已种下一颗幸运草</components_1.Text>
              <components_1.Image src={cloverActive_2x_png_1.default} mode='widthFix' className='icon'/>
            </components_1.View>
            <components_1.View className='footer'>
              <taro_ui_1.AtButton type='primary' size='small'>分享好友获幸运草</taro_ui_1.AtButton>
              
            </components_1.View>
          </components_1.View>
        </taro_ui_1.AtCurtain>


      </components_1.View>);
    }
};
Profile = __decorate([
    redux_1.connect(({ goods }) => ({
        goods
    }), (dispatch) => ({
        fetchProfile(params, callback) {
            dispatch(goods_1.queryProfile(params, callback));
        },
        fetchUsers(params, callback) {
            dispatch(goods_1.queryUsers(params, callback));
        }
    }))
], Profile);
exports.default = Profile;
//# sourceMappingURL=index.jsx.map